package com.neusoft.excel.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.neusoft.excel.service.ImportExcelService;


@RestController
@EnableAutoConfiguration
public class ImportExcelController {

    @Autowired
    private ImportExcelService importExcelService;

    @PostMapping("import")
    public String importExcel(@RequestParam("file") MultipartFile file){
        String fileName = file.getOriginalFilename();
        String message = "成功";
        try {
            importExcelService.batchImport(fileName, file);
        } catch (Exception e) {
            e.printStackTrace();
            message = e.getMessage();
        }
        return message;
    }

}
